package com.company;

import org.omg.CORBA.PUBLIC_MEMBER;

import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Henry on 2018/4/22.
 */
public class HttpServer  {
    public static final int THREAD_NUM = 50;
    private File rootFile ;
    private int port;
    private String indexFileName = "index.html";
    public HttpServer(int port) {
        this.port = port;
    }
    public void start()throws IOException {
        ExecutorService pool = Executors.newFixedThreadPool(THREAD_NUM);
        try (ServerSocket serverSocket = new ServerSocket(port)) {
            while (true) {
                try {
                    Socket socket = serverSocket.accept();
                    Runnable runnable = new RequestHandle(socket);
                    pool.submit(runnable);
                }catch(IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        try {
            HttpServer server = new HttpServer(80);
            server.start();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

}
